using System;
using System.Text.RegularExpressions;

using DesignByContract;

namespace Outcoding.GraphGenerator.Entities {
    public class ValueAxis : IAxis{

        #region Private Helper Classes (1)
        private class Constants {
            public const string DEFAULT_FONT_NAME = "Arial";
            public const int DEFAULT_FONT_SIZE = 12;
            public const bool DEFAULT_FONT_DECORATION_VALUE = false;
            public const bool DEFAULT_VISIBLE_VALUE = true;
            public const string DEFAULT_FONT_COLOR = @"#000000";
        }
        #endregion

        #region Constructors

        public ValueAxis() {
            mColor = Util.ColorTranslation(Constants.DEFAULT_FONT_COLOR);
        }

        #endregion

        private string mFontName = Constants.DEFAULT_FONT_NAME;

        private int mFontSize = Constants.DEFAULT_FONT_SIZE;

        private bool mIsFontBold = true;
        private bool mIsFontItalic = Constants.DEFAULT_FONT_DECORATION_VALUE;
        private bool mIsFontUnderline = Constants.DEFAULT_FONT_DECORATION_VALUE;

        private MinValue mMin;

        private Scale mScale;

        private MaxValue mMax;

        private Label mTitle;

        public MinValue Min {
            get { return mMin; }
            set { mMin = value; }
        }

        public MaxValue Max {
            get { return mMax; }
            set { mMax = value; }
        }

        public Scale Scale {
            get { return mScale; }
            set { mScale = value; }
        }

        public Label Title {
            get { return mTitle; }
            set { mTitle = value; }
        }

        private string mCurrencyString;

        public string CurrencyString {
            get { return mCurrencyString; }
            set {
                if (!String.IsNullOrEmpty(value))
                    mCurrencyString = value;
                else
                    mCurrencyString = String.Empty;
            }
        }

        private string mDecimalSpaces;

        public string DecimalSpaces {
            get { return mDecimalSpaces; }
            set {
                Regex regZeros = new Regex("0*");
                if (regZeros.IsMatch(value))
                    mDecimalSpaces = value;
                else
                    mDecimalSpaces = String.Empty;
            }
        }

        private bool mHasNegativePrefix;

        public bool HasNegativePrefix {
            get { return mHasNegativePrefix; }
            set { mHasNegativePrefix = value; }
        }

        private string mNegativePrefix = "-";

        public string NegativePrefix {
            get {
                if (mHasNegativePrefix)
                    return mNegativePrefix;
                else
                    return String.Empty;
            }
        }

        private bool mHasPercentSufix;

        public bool HasPercentSufix {
            get { return mHasPercentSufix; }
            set { mHasPercentSufix = value; }
        }

        private string mPercentSufix = "%";

        public string PercentSufix {
            get {
                if (HasPercentSufix)
                    return mPercentSufix;
                else
                    return String.Empty;
            }
        }

        //blank space as default separator
        private string mThousandsSeparator = String.Empty;

        public string ThousandsSeparator {
            get {
                return mThousandsSeparator;
            }
            set {
                mThousandsSeparator = value;
            }
        }

        private MajorGridline mMajorGrid;

        public MajorGridline MajorGrid {
            get { return mMajorGrid; }
            set { mMajorGrid = value; }
        }

        public string FontName {
            get {
                return mFontName;
            }
            set {
                mFontName = value;
            }
        }

        public int FontSize {
            get {
                return mFontSize;
            }
            set {
                Check.Ensure(value > 0, "Size value cannot be less than zero.", new ArgumentOutOfRangeException());
                mFontSize = value;
            }
        }

        public bool IsFontBold {
            get {
                return mIsFontBold;
            }
            set {
                mIsFontBold = value;
            }
        }

        public bool IsFontItalic {
            get {
                return mIsFontItalic;
            }
            set {
                mIsFontItalic = value;
            }
        }

        public bool IsFontUnderline {
            get {
                return mIsFontUnderline;
            }
            set {
                mIsFontUnderline = value;
            }
        }

        private long mColor;

        public long Color
        {
            get { return mColor; }
            set { mColor = value; }
        }
    }
}
